# 设置默认的库路径
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
    set(LIB_PATH "${PROJECT_ROOT_DIR}/3rdparty/lib/windows/x64/${CMAKE_BUILD_TYPE}" CACHE PATH  "Path to third-party libraries")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
    set(LIB_PATH "/usr/local/lib/gcc4/x64/${CMAKE_BUILD_TYPE}" CACHE PATH  "Path to third-party libraries")
endif()
# 设置库路径的变量（使用 FILEPATH 类型，避免路径错误）
set(LIBFBX_PATH "" CACHE FILEPATH "Path to FBX SDK library")
set(LIBXML_PATH "" CACHE FILEPATH "Path to XML library")
set(ZLIB_PATH "" CACHE FILEPATH "Path to Zlib library")

# Windows 环境库路径配置
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
    if(NOT LIBFBX_PATH)
        set(LIBFBX_PATH "${LIB_PATH}/libfbxsdk-md.lib")
    endif()
    if(NOT LIBXML_PATH)
        set(LIBXML_PATH "${LIB_PATH}/libxml2-md.lib")
    endif()
    if(NOT ZLIB_PATH)
        set(ZLIB_PATH "${LIB_PATH}/zlib-md.lib")
    endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
    if(NOT LIBFBX_PATH)
        set(LIBFBX_PATH "${LIB_PATH}/libfbxsdk.so")
    endif()
endif()

# 设置工具名称
set(TOOL_NAME "splitFbx")

# 定义可执行文件
add_executable(${TOOL_NAME} main.cpp SplitFbx.cpp SplitFbxByMaterial.cpp Util.cpp "SplitFbxByMaterialWithHierarchy.cpp")

# 包含目录
include_directories(${PROJECT_ROOT_DIR}/3rdparty/include ${PROJECT_ROOT_DIR}/include)

# 链接库
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
        target_link_libraries(${TOOL_NAME} 
        ${LIBFBX_PATH} 
        ${LIBXML_PATH} 
        ${ZLIB_PATH})
    elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
        target_link_libraries(${TOOL_NAME} ${LIBFBX_PATH})
    endif()
else()
    if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
        target_link_libraries(${TOOL_NAME} 
        ${LIBFBX_PATH} 
        ${LIBXML_PATH} 
        ${ZLIB_PATH})
    elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
        target_link_libraries(${TOOL_NAME} ${LIBFBX_PATH})
    endif()
endif()

# 安装目标
install(TARGETS ${TOOL_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
